// pages/index/shopInfo.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    data: {},
    loading: 0,
    disabled: 0,
    order_sn:"",
    userInfo:{},
    region:[],
    user_tag:0,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var type = options.type;
    app.getUserInfo((info)=>{
      this.data.userInfo = info
      console.log(info);
      this.setData({user_tag: info.store_member.user_tag});
    })
   
  },
  
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },
  
  setVal: function (e) {
    var name = e.currentTarget.dataset.name;
    var v = e.detail.value;
    var data = this.data.data;
    data[name] = v;
    this.setData({
      data: data
    });
  },
  
  formSubmit: function (e) {
    var postData = e.detail.value;
    var data = this.data.data;
    for (var i in postData) {
      data[i] = postData[i];
    }
    if (this.data.region.length==0){
      app.alert("请选择合作区域");
      return;
    }
    data["region"] = this.data.region[1];
    
    //手机号登陆
    var that = this;
    that.setData({
      loading: 1,
      disabled: 1
    });
    data.method = "POST";
    data.openid = that.data.userInfo.openid;
    app.api("apiv2/member_partner/add", data, function (res) {
      that.setData({
        loading: 0,
        disabled: 0
      });
      if (res.code != 200) {
        app.alert(res.msg);
        return;
      }
      app.setPageData("user/partnerList", { reload: 1 });
      wx.navigateBack();
      // that.data.order_sn = res.data;
      // that.pay();
      
    });
  },
  pay: function () {
    var order_sn = this.data.order_sn;
    app.api("apiv2/pay/run", { order_sn: order_sn, getJson: 1, paytype:"pay.weixin.jspay"}, function (res) {
      if (res.code != 200) {
        app.alert(res.msg);
        return;
      }
      var PayInfo = JSON.parse(res.data.PayInfo);
      PayInfo.success = function (res) {
        app.setPageData("user/partnerList", { reload: 1 });
        wx.navigateBack();
      };
      PayInfo.fail = function (res) {
        console.log(res);
      };

      wx.requestPayment(PayInfo);
    })
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },
  bindRegionChange:function(e){
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      region: e.detail.value
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.getShopInfo();
    wx.stopPullDownRefresh();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})